﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


public class ApiIsLoginAttribute : AuthorizeAttribute
{
    /// <summary>
    /// 判断用户是否已经登录
    /// </summary>
    /// <param name="httpContext"></param>
    /// <returns></returns>
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        var userinfo = LoginModel.User;
        if (userinfo == null || userinfo.Uid == 0)
        {
            httpContext.Response.Buffer = true;
            httpContext.Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
            httpContext.Response.Expires = 0;
            httpContext.Response.CacheControl = "no-cache";
            httpContext.Response.AddHeader("Pragma", "No-Cache");
            httpContext.Response.ContentType = "javascript";
            httpContext.Response.Write("showloginDialog()");
            httpContext.Response.End();
            return false;
        }
        return true;
    }
}
